package com.njwb.day15.zqzb.method;

import com.njwb.day15.zqzb.method.review.Person;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;

public class MethodDemo02 {
    public static void main(String[] args) {

        //根据具体的方法名找方法


        try {
            Method m = Person.class.getDeclaredMethod("test02",String.class,int.class);
            System.out.println(m.getName());
            System.out.println(m.getReturnType());
            System.out.println(Modifier.toString(m.getModifiers()));
            Class[] paramTypes=  m.getParameterTypes();
            System.out.println(Arrays.toString(paramTypes));
            m.setAccessible(true);

            //调用方法

            m.invoke(new Person(),"hello",123);



        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }


    }
}
